# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Project      :commercial_opportunity_zhu
# @FileName     :ProjectBusiness.py
# @Time         :2021-11-11 13:56:27
# @Author       :@HaoWei
# @Desc         :

from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
from main_process import TaskPublic
from PubilcTask.Common.CommonBusiness import CommonBusiness


class ProjectBusiness(TaskPublic.TaskPublic):

    def change_dev(self):
        """
        :param 商机系统dev环境0924
        :return:
        """
        CommonBusiness.change_tree(self.b)
        self.b.find_element_by_id('dt3').click()
        self.logger.info("商机系统dev环境0924")

    def business_add_project_approval(self):
        """
        :param 商机中增加新的立项
        :return:
        """
        try:
            self.b.find_element_by_id('tree3_62').click()
            self.b.find_element_by_id('tree3_7964').click()
            self.b.find_element_by_id('tree3_7966').click()
            self.b.switch_to.default_content()
            self.b.switch_to.frame('ifDefault')
            self.b.switch_to.frame('frmContent')
            self.b.switch_to.frame(self.b.find_element_by_css_selector('#content > frame:nth-child(2)'))
            self.b.find_element_by_css_selector(
                '#app > div > div > div > div > div.filter-container > div.el-card.box-card.is-always-shadow > div.el-card__body > div > form > div.el-row > span:nth-child(5) > div > div > div > div > input').send_keys(
                'T104HQVY')
            self.b.find_element_by_css_selector(
                '#app > div > div > div > div > div.filter-container > div.el-card.box-card.is-always-shadow > div.el-card__body > div > div > button').click()
            two = self.b.find_element_by_xpath(
                '//*[@id="app"]/div/div/div/div/div[1]/div[2]/div/div[2]/div[3]/table/tbody/tr')
            ActionChains(self.b).double_click(two).perform()
            sleep(5)
            self.b.find_element_by_xpath('/html/body/div[1]/div/div/div/div/div[2]/form/div/div/div[1]').click()
            sleep(5)
            self.b.find_element_by_xpath('/html/body/div[1]/div/div/div/div/div[3]/form/div[1]/div[3]').click()
            sleep(3)
            self.logger.info("商机中增加新的立项")
        except Exception as e:
            self.logger.error("商机中增加新的立项", e)

    def approve_initiate_project(self):
        """
        :param 填写立项信息
        :return:
        """
        try:
            self.b.find_element_by_xpath(
                '0/html/body/div[1]/div/div/div/div/div[3]/form/div[2]/div/div[2]/div/div/div[1]/div/div/div/div/div/input').click()
            # 选择《ThinkCentre M及启天产品(03)》选择这个产品组信息
            sleep(3)
            self.b.find_element_by_xpath(
                '/html/body/div[@class="el-select-dropdown el-popper"]/div[1]/div[1]/ul/li[1]').click()
            sleep(3)
            # 定位立项目的
            self.b.find_element_by_xpath(
                '/html/body/div[1]/div/div/div/div/div[3]/form/div[2]/div/div[2]/div/div/div[3]/div[1]/div/div/div/div/input').click()
            sleep(3)
            # 选择其他
            self.b.find_element_by_xpath(
                '/html/body/div[@class="el-select-dropdown el-popper"][2]/div[1]/div[1]/ul/li[3]').click()
            sleep(3)
            self.logger.info("填写立项信息success")
        except Exception as e:
            self.logger.error("填写立项信息", e)

    def selling_format(self):
        """
        :param 填写销售方式
        :return:
        """
        try:
            self.b.find_element_by_xpath(
                '/html/body/div[1]/div/div/div/div/div[3]/form/div[2]/div/div[2]/div/div/div[3]/div[2]/div/div/div/div').click()
            sleep(3)
            self.logger.info("填写销售方式success")
        except Exception as e:
            self.logger.error("填写销售方式", e)


if __name__ == "__main__":
    run_code = 0
